import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _regeneratorRuntime from "@babel/runtime/regenerator";
var _excluded = ["page", "size"];

/**
 * @date: 2018-09-24

 */
import { queryMapIdpValue } from 'cpaas-front/lib/services/api';
import { getResponse } from 'utils/utils';
import { queryFileList as _queryFileList } from "../services/fileAggregateService";
export default {
  namespace: 'fileAggregate',
  state: {
    fileData: {},
    // 文件列表
    fileTypeList: [],
    // 文件类型
    fileFormatList: [],
    // 文件格式
    fileUnitList: [],
    // 单位
    sourceList: [],
    // 来源类型
    detailWordEditor: {// [record.fileUrl]: record, // 存储 word编辑 的记录
    }
  },
  effects: {
    // 获取初始化数据
    init: /*#__PURE__*/_regeneratorRuntime.mark(function init(_ref, _ref2) {
      var payload, call, put, lovCodes, res, fileTypeList, fileFormatList, fileUnitList, sourceList;
      return _regeneratorRuntime.wrap(function init$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              payload = _ref.payload;
              call = _ref2.call, put = _ref2.put;
              lovCodes = payload.lovCodes;
              _context.t0 = getResponse;
              _context.next = 6;
              return call(queryMapIdpValue, lovCodes);

            case 6:
              _context.t1 = _context.sent;
              res = (0, _context.t0)(_context.t1);

              if (!res) {
                _context.next = 12;
                break;
              }

              fileTypeList = res.fileTypeList, fileFormatList = res.fileFormatList, fileUnitList = res.fileUnitList, sourceList = res.sourceList;
              _context.next = 12;
              return put({
                type: 'updateState',
                payload: {
                  fileTypeList: fileTypeList,
                  fileFormatList: fileFormatList,
                  fileUnitList: fileUnitList,
                  sourceList: sourceList
                }
              });

            case 12:
            case "end":
              return _context.stop();
          }
        }
      }, init);
    }),
    // 获取文件列表
    queryFileList: /*#__PURE__*/_regeneratorRuntime.mark(function queryFileList(_ref3, _ref4) {
      var payload, call, put, _payload$page, page, _payload$size, size, params, res, list;

      return _regeneratorRuntime.wrap(function queryFileList$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              payload = _ref3.payload;
              call = _ref4.call, put = _ref4.put;
              _payload$page = payload.page, page = _payload$page === void 0 ? 0 : _payload$page, _payload$size = payload.size, size = _payload$size === void 0 ? 10 : _payload$size, params = _objectWithoutProperties(payload, _excluded);
              _context2.next = 5;
              return call(_queryFileList, _objectSpread({
                page: page,
                size: size
              }, params));

            case 5:
              res = _context2.sent;
              list = getResponse(res);

              if (!list) {
                _context2.next = 10;
                break;
              }

              _context2.next = 10;
              return put({
                type: 'updateState',
                payload: {
                  fileData: list
                }
              });

            case 10:
            case "end":
              return _context2.stop();
          }
        }
      }, queryFileList);
    })
  },
  reducers: {
    updateState: function updateState(state, action) {
      return _objectSpread(_objectSpread({}, state), action.payload);
    }
  }
};